<template>
  <!--
   现在需要写鼠标移入移出效果,移入到li上删除按钮显示,并有背景色 
   1.给li增加一个active的类名,设置样式
   2.
   -->
  <!-- 把两个事件函数分开 -->
  <!-- <li
    :class="isEnter ? 'active' : ''"
    @mouseenter="mouseEnterHandle"
    @mouseleave="mouseLeaveHandle"
  > -->

  <li
    :class="isEnter ? 'active' : ''"
    @mouseenter="mouseChangeHandle('enter')"
    @mouseleave="mouseChangeHandle('leave')"
  >
    <label>
      <!-- 单选框选中逻辑.给input绑定点击事件,传入唯一的id,然后去App中判断 -->
      <input type="checkbox" :checked="done" @click='singleCheckHandle(id)' />
      <!-- 2.展示列表中每一项数据 -->
      <span>{{ thing }}</span>
    </label>
    <button class="btn btn-danger" @click='singleDeleteHandle(id)'>删除</button>
  </li>
</template>

<script>
export default {
  name: "Item",
  //1.porps将列表中的数据接收过来
  props: ["id", "thing", "done",'singleCheckHandle','singleDeleteHandle'],

  data() {
    return {
      isEnter: false,
    };
  },
  methods: {
    //两个事件的事件函数分开的写法
    /* mouseEnterHandle() {
      this.isEnter = true;
    },
    mouseLeaveHandle() {
      this.isEnter = false;
    }, */

    //鼠标的两个事件事件函数合并一起
    mouseChangeHandle(type) {
      // this.isEnter = type === "enter" ? true : false;
      this.isEnter = type === "enter";
    },
  },
};
</script>

<style scoped>
/*item*/
li {
  list-style: none;
  height: 36px;
  line-height: 36px;
  padding: 0 5px;
  border-bottom: 1px solid #ddd;
}

li label {
  float: left;
  cursor: pointer;
}

li label li input {
  vertical-align: middle;
  margin-right: 6px;
  position: relative;
  top: -1px;
}

li button {
  float: right;
  display: none;
  margin-top: 3px;
}

li:before {
  content: initial;
}

li:last-child {
  border-bottom: none;
}

li.active {
  background: #ccc;
}

li.active button {
  display: block;
}
</style>